#!/bin/bash

APP_DIR=$1

if [ ! -d "$APP_DIR" ]
then
    mkdir $APP_DIR
fi

cd $APP_DIR || exit 1

JAR_NAME=`ls | grep jar`

if [ -f tpid ]
then
	APP_PID=$(cat tpid)
	echo "kill pid $APP_PID"
	kill -9 $APP_PID || echo "kill pid $APP_PID failed."
	rm tpid || echo "rm pid file failed."
else
	echo "no pid file."
fi

if [ -n "$JAR_NAME" ]
then
    echo "stop $JAR_NAME"
    rm $JAR_NAME || echo "rm jar file failed."
else
    echo "no jar file."
fi
